package com.zb.wx.event;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.wxinf.rece.pojo.request.event.BaseEventRequest;
import com.wxinf.rece.pojo.request.event.SubscribeEventRequest;
import com.wxinf.rece.pojo.response.Article;
import com.wxinf.rece.pojo.response.message.BaseMessageResponse;
import com.wxinf.rece.pojo.response.message.NewsMessageResponse;
import com.wxinf.rece.press.IWXEventExecutor;
import com.wxinf.utils.WXConstants;

public class SubscribeEventExecutor implements IWXEventExecutor{
    
    private Logger logger = LoggerFactory.getLogger(this.getClass().getName());
    
    @Override
    public BaseMessageResponse executor(BaseEventRequest baseEventRequest) {
    	logger.debug("[获取关注事件：]" + baseEventRequest);
        
    	// 获取关注事件请求类
        SubscribeEventRequest subscribeEventRequest = (SubscribeEventRequest)baseEventRequest;
        
        //消息类型，event
        String msgType = subscribeEventRequest.getMsgType();
        logger.debug("msgType:" + msgType);
        
        //subscribe(订阅)
        String event = subscribeEventRequest.getEvent();
        logger.debug("event:" + event);
        
        //openid
        String fromUserName = subscribeEventRequest.getFromUserName();
        logger.debug("fromUserName:" + fromUserName);
        
        //开发者微信号
        String toUserName = subscribeEventRequest.getToUserName();
        logger.debug("toUserName:" + toUserName);
        
        //消息创建时间 （整型） 
        Long createTime = subscribeEventRequest.getCreateTime();
        logger.debug("createTime:" + createTime);
        
        
        //返回欢迎文本消息
        /*
        TextMessageResponse textMessageResponse = new TextMessageResponse();
        textMessageResponse.setFromUserName(toUserName);
        textMessageResponse.setToUserName(fromUserName);
        textMessageResponse.setMsgType(WXConstants.RSP_MESSAGE_TYPE_TEXT);
        textMessageResponse.setCreateTime(System.currentTimeMillis());
        textMessageResponse.setContent("Hi，感谢关注车到用车，从今天开始，我们将为您提供24小时专车接送服务。");
        return textMessageResponse;
        */
        
        // 创建图文消息
        NewsMessageResponse newsMessage = new NewsMessageResponse();
        newsMessage.setToUserName(fromUserName);
        newsMessage.setFromUserName(toUserName);
        newsMessage.setCreateTime(new Date().getTime());
        newsMessage.setMsgType(WXConstants.RSP_MESSAGE_TYPE_NEWS);
        //newsMessage.setFuncFlag(0);
        
        Article article1 = new Article();
        article1.setTitle("[JAVA技术分享] 欢迎关注我的个人公众号^_^");
        article1.setPicUrl("https://mp.weixin.qq.com/misc/getheadimg?token=1129909443&fakeid=3088733098&r=973383");
        article1.setUrl("http://www.2b2b92b.com");

        Article article2 = new Article();
        article2.setTitle("[博客网址] www.2b2b92b.com");
        article2.setPicUrl("https://mp.weixin.qq.com/misc/getheadimg?token=1129909443&fakeid=3088733098&r=973383");
        article2.setUrl("http://www.2b2b92b.com");

        Article article3 = new Article();
        article3.setTitle("［联系邮箱］842324724@qq.com");
        article3.setPicUrl("https://mp.weixin.qq.com/misc/getheadimg?token=1129909443&fakeid=3088733098&r=973383");
        article3.setUrl("http://www.2b2b92b.com");
        
        Article article4 = new Article();
        article4.setTitle("提倡开源，分享快乐。");
        article4.setPicUrl("https://mp.weixin.qq.com/misc/getheadimg?token=1129909443&fakeid=3088733098&r=973383");
        article4.setUrl("http://www.2b2b92b.com");
        
        Article article5 = new Article();
        article5.setTitle("共同进步，共同学习。");
        article5.setPicUrl("https://mp.weixin.qq.com/misc/getheadimg?token=1129909443&fakeid=3088733098&r=973383");
        article5.setUrl("http://www.2b2b92b.com");
        
        
        List<Article> articleList = new ArrayList<Article>();
        articleList.add(article1);
        articleList.add(article2);
        articleList.add(article3);
        articleList.add(article4);
        articleList.add(article5);
        newsMessage.setArticleCount(articleList.size());
        newsMessage.setArticles(articleList);
        //respMessage = MessageUtil.newsMessageToXml(newsMessage);
        return newsMessage;
    }
}
